/*
 * CacheUtils.c
 *
 *  Created on: Mar 26, 2012
 *      Author: kody
 */
#include "simutils.h"
#include "config.h"
#include "cache.h"

void initResults(results_s * results)
{
	memset(results,0,sizeof(results_s));
}
void printResults(results_s * results)
{
        printf("--------------------------------------------------------------------------\n");
        printf("                         Simulation Results                               \n");
        printf("--------------------------------------------------------------------------\n");
        /*Print out Memory System Configuration*/
        printConfig();

        /*Print out Exec time and Refs information*/
        printf("Execute time = %llu     Total Refs = %lu\n",
                        results->executeTime,
                        (results->dataRefs+results->instRefs));
        printf("Instruction Refs = %ld     Data Refs = %ld\n",
                                results->instRefs,
                                results->dataRefs);
        /*Print out Number of Instructions and Percentage*/
        printf("Number of Instructions:     [Percentage]\n");
        printf("   Loads (L) = %llu    [%2.2f%%]   :   Stores (S) = %llu    [%2.2f%%]\n",
                        results->numInstr.numLoad,
                        (float)(results->numInstr.numLoad*100.0/(float)results->numInstr.numTotal),
                        results->numInstr.numStore,
                        (float)(results->numInstr.numStore*100.0/(float)results->numInstr.numTotal));
        printf("   Branch (B) = %llu    [%2.2f%%]   :   Computation (C) = %llu    [%2.2f%%]\n",
                                results->numInstr.numBranch,
                                (results->numInstr.numBranch*100.0/(float)results->numInstr.numTotal),
                                results->numInstr.numComp,
                                (results->numInstr.numComp*100.0/(float)results->numInstr.numTotal));
        printf("   Total = %llu\n",results->numInstr.numTotal);
        /*Print out Cycles time and Refs information*/
        printf("Cycles for Instructions:     [Percentage]\n");
        printf("   Loads (L) = %llu    [%2.2f%%]   :   Stores (S) = %llu    [%2.2f%%]\n",
                        results->cycleInstr.cycleLoad,
                        (float)(results->cycleInstr.cycleLoad*100.0/(float)results->cycleInstr.cycleTotal),
                        results->cycleInstr.cycleStore,
                        (float)(results->cycleInstr.cycleStore*100.0/(float)results->cycleInstr.cycleTotal));
        printf("   Branch (B) = %llu    [%2.2f%%]   :   Computation (C) = %llu    [%2.2f%%]\n",
                                results->cycleInstr.cycleBranch,
                                (results->cycleInstr.cycleBranch*100.0/(float)results->cycleInstr.cycleTotal),
                                results->cycleInstr.cycleComp,
                                (results->cycleInstr.cycleComp*100.0/(float)results->cycleInstr.cycleTotal));
        printf("   Total = %llu\n",results->cycleInstr.cycleTotal);

        /*Print out CPI information*/
        printf("Cycles per Instruction (CPI):\n");
        printf("   Loads (L) = %2.2f      :   Stores (S) = %2.2f\n",
                        (float)(results->cycleInstr.cycleLoad / (float)results->numInstr.numLoad),
                        (float)(results->cycleInstr.cycleStore / (float)results->numInstr.numStore));
        printf("   Branch (B) = %2.2f     :   Computation (C) = %2.2f\n",
        		(float)(results->cycleInstr.cycleBranch / (float)results->numInstr.numBranch),
        		(float)(results->cycleInstr.cycleComp / (float)results->numInstr.numComp));
        printf("   Overall = %2.2f\n",(float)(results->cycleInstr.cycleTotal/ (float)results->numInstr.numTotal));

        /*Print out memory level L1I*/
        printf("Memory Level:   L1I\n");
        printf("   Hit Count = %llu     Miss Count = %llu   Total Request = %llu\n",
        		results->hitCount[L1I],
        		results->missCount[L1I],
        		results->accessTotal[L1I]);
        printf("   Hit Rate = %2.2f%%    Miss Rate = %2.2f%%\n",
        		(float)(results->hitCount[L1I]*100/(float)results->accessTotal[L1I]),
        		(float)(results->missCount[L1I]*100/(float)results->accessTotal[L1I]));
        printf("   Kickouts : %lu   Dirty Kickouts : %lu  Transfers : %lu\n",
        		results->kickouts[L1I],
        		results->dirtykickouts[L1I],
        		results->transfers[L1I]);
        /*Print out memory level L1D*/
        printf("Memory Level:   L1D\n");
        printf("   Hit Count = %llu     Miss Count = %llu   Total Request = %llu\n",
        		results->hitCount[L1D],
        		results->missCount[L1D],
        		results->accessTotal[L1D]);
        printf("   Hit Rate = %2.2f%%    Miss Rate = %2.2f%%\n",
        		(float)(results->hitCount[L1D]*100/(float)results->accessTotal[L1D]),
        		(float)(results->missCount[L1D]*100/(float)results->accessTotal[L1D]));
        printf("   Kickouts : %lu   Dirty Kickouts : %lu  Transfers : %lu\n",
        		results->kickouts[L1D],
        		results->dirtykickouts[L1D],
        		results->transfers[L1D]);
        /*Print out memory level L2*/
        printf("Memory Level:   L2\n");
        printf("   Hit Count = %llu     Miss Count = %llu   Total Request = %llu\n",
        		results->hitCount[L2],
        		results->missCount[L2],
        		results->accessTotal[L2]);
        printf("   Hit Rate = %2.2f%%    Miss Rate = %2.2f%%\n",
        		(float)(results->hitCount[L2]*100/(float)results->accessTotal[L2]),
        		(float)(results->missCount[L2]*100/(float)results->accessTotal[L2]));
        printf("   Kickouts : %lu   Dirty Kickouts : %lu  Transfers : %lu\n",
        		results->kickouts[L2],
        		results->dirtykickouts[L2],
        		results->transfers[L2]);
}
